package src.mock.tomcat;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;

public class MockResponse {
    private OutputStream outputStream;
    public MockResponse(OutputStream outputStream){
        this.outputStream=outputStream;
    }
    public void write(String content) throws IOException {
        StringBuffer httpResponse=new StringBuffer();
        httpResponse.append("HTTP/1,1 200 OK\n").append("Content-Type:text/html\n").
                append("\r\n")
                .append("<html><body>")
                .append("<style type=\"text/css\">\n" +
                        "h1 {color: black\n" +
                        "p {color: blue}\n" +
                        "</style>")
                .append("<h1>MockServer Test</h1>").append("<h1>").append(new Date().toString())
                .append("</h1><h1>")
                .append(content)
                .append("</h1>")
                .append("</body></html>");
        byte[] resp=httpResponse.toString().getBytes();
        outputStream.write(resp,0,resp.length);
        outputStream.close();
    }
}
